<?php class Mod_comment extends CI_Model {
	
	function __construct()
	    {
		parent::__construct();
	    }
         /*retourner id_com - id_pa - date_post pour une clinique*/
        function getPostByIdClinic($id_cli){
            $sql = "SELECT * FROM poster WHERE ID_CLI = $id_cli ORDER BY DATE_POST ASC";
            $data=array();
            $Q = $this->db->query($sql);
            if ($Q->num_rows()>0){
                    foreach ($Q->result_array() as $row){
                            $data[]=$row;
                    }
            }
            $Q->free_result();
            return $data;
        }
         /*retourner le commentaire*/
        function getCommentById($id_com){
            $sql = "SELECT CONTENU_COM FROM commentaire WHERE ID_COM = $id_com";
            $com='';
            $Q = $this->db->query($sql);
            if ($Q->num_rows()>0){
                    foreach ($Q->result_array() as $row){
                            $com=$row['CONTENU_COM'];
                    }
            }
            $Q->free_result();
            return $com;
        }
        /*retourner l'identite des patients qui ont commentés*/
        function getPatientById($id_pa){
            $sql = "SELECT * FROM patient WHERE ID_PA ='$id_pa'";
            $data=array();
            $Q = $this->db->query($sql);
            if ($Q->num_rows()>0){
                    foreach ($Q->result_array() as $row){
                            $data[]=$row;
                    }
            }
            $Q->free_result();
            return $data;
            
        }
        /*supprimer un commentaire*/
        function delComment($id_com){
            return $this->db->delete("commentaire",array("ID_COM"=>$id_com));            
        }
        function validComment($id_com){
            $data = array(
				'ID_COM' => $id_com,
				'ETAT_COM' => 1
			);
	    $this->db->where('ID_COM',$id_com);
	    $this->db->update('commentaire', $data);          
        }
}